package com.yiban.demo.LoginUser.Entity;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
public enum ROLE{

    
    ADMIN(3,"admin"),
    USER(1,"user"),
    EVERYBODY(0,"everybody"),
    STATIONADMIN(2,"stationAdmin");

    private int weight;
    /**
     * name必须符合 当name全大写时与枚举名一致
     * 比如 admin 其对应枚举名为ADMIN
     */
    private String name;
    ROLE(int weight,String name){
        this.weight = weight;
        this.name = name;
    }
    public List<String> getLess(){
        final ArrayList<String> list = new ArrayList<>();
        for (ROLE value : ROLE.values()) {
            if (value.weight <= this.weight){
                list.add(value.name);
            }
        }
        return list;
    }

    public static boolean hasRole(String roleName){
        for (ROLE role : ROLE.values()) {
            if (role.name.equals(roleName)) {
                return true;
            }
        }
        return false;
    }
}
